# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 16:45
# @Author  : catherine
# @Email   : catherine_csq@163.com
# @File    : contacts_home_page.py
# @Software: PyCharm
from time import sleep

from selenium.webdriver.common.by import By

from pages.base_page import BasePage


class ContactsHomePage(BasePage):
    '''联系人界面页类'''
    url="http://192.168.189.1:8081/crm/index.php?m=contacts&a=index"
    #定位器
    add_contacts_locator = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div/a/i')
    edit_contacts_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(1) > td:nth-child(10) > a:nth-child(2)')
    selected_contacts_locator = (By.NAME, 'contacts_id[]')
    delete_locator = (By.ID, 'delete')

    def click_add_contacts(self):
        '''新建联系人按钮，将进入新建联系人界面'''
        self.find_element(self.add_contacts_locator).click()

    def click_edit_contacts(self):
        '''编辑联系人按钮，将进入编辑联系人界面'''
        self.find_element(self.edit_contacts_locator).click()

    def delete_contacts(self):
        self.find_element(self.selected_contacts_locator).click()
        self.find_element(self.delete_locator).click()
        sleep(1)
        self.driver.switch_to.alert.accept()